function DispatchvoiceCtrl(){}
import { DispatchCtrlLib } from '../chromeLib/DispatchCtrlLib'
/**
 * 监听终端的状态
 * @param   extnum          分机号
 * @param   type            开始/结束   0-结束监听 1-开始监听
 */

DispatchvoiceCtrl.Monitorstatus=function(extnum,type){
  let ret = DispatchCtrlLib.VoipDispatchMoniterStatus(extnum,type);
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "Monitorstatus";
    let Parm = new Object();
    Parm.extnum = extnum;
    Parm.ret = ret;
    Dispatchvoice(Msg, Parm);   //前端页面处理	ret为0时表示监听成功,-1为失败
  }
}

/**
 * 发起IP通话(绑定话机)
 * @param   extnum          分机号
 */

DispatchvoiceCtrl.MakeAudioCall=function(item){
  item.extnum+=""
  let channelId = DispatchCtrlLib.VoipMakeAudioCall(item.extnum,-1);
    let Msg = "MakeAudioCall";
    let Parm = item;
    Parm.channelId = channelId;
    Dispatchvoice(Msg,Parm);   //前端页面处理	保存channelid 以供后续操作使用
    DispatchvoiceExhale(Parm);   //呼出最近10条数据更新
}

/**
 * 发起IP通话(未绑定话机)
 * @param   extnum          分机号
 */

DispatchvoiceCtrl.MakeAudioCallDC=function(item){
  item.extnum+=""
  let channelId = DispatchCtrlLib.VoipMakeAudioCall(item.extnum);
    let Msg = "MakeAudioCall";
    let Parm = item;
    Parm.channelId = channelId;
    Dispatchvoice(Msg,Parm);   //前端页面处理	保存channelid 以供后续操作使用
    DispatchvoiceExhale(Parm);   //呼出最近10条数据更新
}
/**
 * 消息模块发起IP通话
 * @param   extnum          分机号
 */

DispatchvoiceCtrl.msgMakeAudioCall=function(item){
  item.extnum+=""
  let channelId = DispatchCtrlLib.VoipMakeAudioCall(item.extnum);
  if(channelId==-3){
    console.log("参数错误");
    return 0;
  }else{
    let Msg = "msgMakeAudioCall";
    let Parm = item;
    Parm.channelId = channelId;
    DispatchMessage(Msg,Parm);   //前端页面处理	保存channelid 以供后续操作使用
    return 1;
  }
}

/**
 * 挂断IP通话
 * @param   channelId          通道标识
 */

DispatchvoiceCtrl.HangupCall=function(channelId){
  let ret = DispatchCtrlLib.VoipHangupCall(channelId);
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "HangupCall";
    let Parm = new Object();
    Parm.ret = ret;
    Parm.channelId = channelId;
    Dispatchvoice(Msg, Parm);   //参数校验结果
  }
  return ret;
}

/**
 * IP调度接听台席来电(绑定话机)
 * @param   ExtNumInFifo            呼叫队列中成员的分机号
 */

DispatchvoiceCtrl.VoipDispatchAnswerFifo=function(item){
  item.extnum+=""
  let ret =DispatchCtrlLib.VoipDispatchAnswerFifo(item.extnum,-1);
    let Msg = "DispatchAnswerFifo";
    let Parm = item;
    Parm.ret = ret;
    Parm.extnum = item.extnum;
    Dispatchvoice(Msg,Parm);
}

/**
 * IP调度接听台席来电（未绑定话机）
 * @param   ExtNumInFifo            呼叫队列中成员的分机号
 */

DispatchvoiceCtrl.VoipDispatchAnswerFifoDC=function(item){
  item.extnum+=""
  let ret =DispatchCtrlLib.VoipDispatchAnswerFifo(item.extnum);
    let Msg = "DispatchAnswerFifo";
    let Parm = item;
    Parm.channelId = ret;
    Parm.extnum = item.extnum;
    Dispatchvoice(Msg,Parm);
}
/**
 * IP通话呼叫保持
 * @param   channelId          通道标识
 * @param   type          类型     0-恢复通话 1-呼叫保持
 * @param   obj          判断是否是在接听台席来电的时候操作   如果undefined则是正常保持   如果非undefined则是接听来电的时候先手动保持当前通话
 */

DispatchvoiceCtrl.HoldCall=function(channelId,type,obj){
  let ret =DispatchCtrlLib.VoipHoldCall(channelId,type);
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "HoldCall";
    let Parm = new Object();
    if(obj){
      Parm = obj;
      Parm.msg = "answerFifo"
    }else{
      Parm.msg = "normal"
    }
    Parm.ret = ret;
    Dispatchvoice(Msg,Parm);   //前端页面处理	ret>-1 成功  ret=-1失败
  }
  return ret;
}


/**
 * IP通话呼叫转移
 * @param   channelId          通道标识
 * @param   extnum            要转接的分机号
 */

DispatchvoiceCtrl.TransferCall=function(channelId,extnum){
  var ret =DispatchCtrlLib.VoipTransferCall(channelId,extnum);
  var Msg = "TransferCall";
  var Parm = new Object();
  Parm.channelId = channelId;
  Parm.extnum = extnum;
  Parm.ret = ret;
  Dispatchvoice(Msg,Parm); //前端页面处理	ret>-1 成功  ret=-1失败  转接的extnum保存
return ret;
}


/**
 * IP调度:强插呼叫
 * @param   extnum            要转接的分机号
 */
DispatchvoiceCtrl.SubstituteForcing=function(extnum){
    let ret =DispatchCtrlLib.VoipDispatchInsertCall(extnum,-1);
 // 整型。小于0 —— 参数错误；大于0 —— 呼叫标识。
    let Msg = "SubstituteForcing";
    let Parm = new Object();
    Parm.extnum = extnum;
    Dispatchvoice(Msg, Parm);
}
/**
 * IP调度:强拆呼叫
 * @param   extnum            强拆的分机号
 */
DispatchvoiceCtrl.SubstituteForcedDemolition=function(extnum){
    let ret =DispatchCtrlLib.VoipDispatchInterruptCall(extnum);
 // 整型。小于0 —— 参数错误；大于0 —— 呼叫标识。
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "SubstituteForcedDemolition";
    let Parm = new Object();
    Parm.extnum = extnum;
    Dispatchvoice(Msg, Parm);
  }
}/**
 * 6.3.13IP调度监听呼叫
 * @param   extnum            要监听的分机号
 */
DispatchvoiceCtrl.SubstituteAgentMonitoring=function(extnum){
    let ret =DispatchCtrlLib.VoipDispatchMoniterCall(extnum,-1);
    let Msg = "SubstituteAgentMonitoring";
    let Parm = new Object();
    Parm.extnum = extnum;
    Dispatchvoice(Msg, Parm);
}
/**
 * 强断
 * @param   extnum            强断的分机号
 */
DispatchvoiceCtrl.SubstituteForciblyBreak=function(extnum){
    let ret =DispatchCtrlLib.VoipDispatchInterruptCall(extnum);
 // 整型。小于0 —— 参数错误；大于0 —— 呼叫标识。
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "SubstituteForciblyBreak";
    let Parm = new Object();
    Parm.extnum = extnum;
    Dispatchvoice(Msg, Parm);
  }
}
/**
 * 强拆
 * @param   extnum            要转接的分机号
 */
DispatchvoiceCtrl.VoipDispatchBreakCall=function(extnum,DcPhone){
    let ret =DispatchCtrlLib.VoipDispatchBreakCall(extnum,DcPhone);
    let Msg = "VoipDispatchBreakCallReq";
    let Parm = new Object();
    Parm.extnum = extnum;
}
/**
 * IP通话呼叫代接
 * @param   channelId          通道标识
 * @param   extnum            要转接的分机号
 */
DispatchvoiceCtrl.SubstituteCall=function(extnum){
    let channelId =DispatchCtrlLib.VoipDispatchSubstituteCall(extnum,-1);
    let Msg = "SubstituteCall";
    let Parm = new Object();
    Parm.channelId = channelId;
    Parm.extnum = extnum;
    Dispatchvoice(Msg,Parm); //前端页面处理	ret>-1 成功  ret=-1失败  代接的extnum和channelId保存
}

/**
 * 监听IP通话
 * @param   extnum            要监听的分机号
 */

DispatchvoiceCtrl.MonitorCall=function(extnum){
  var channelId =DispatchCtrlLib.VoipDispatchMoniterCall(extnum,-1);
  var Msg = "MonitorCall";
  var Parm = new Object();
  Parm.channelId = channelId;
  Parm.extnum = extnum;
  Dispatchvoice(Msg,Parm); //前端页面处理	ret>-1 成功  ret=-1失败  监听的extnum和channelId保存
}

/**
 * 转接多方
 * @param   ExtNum            分机号
 * @param   ConfID            会议ID
 */

DispatchvoiceCtrl.CallToConference=function(ExtNum,ConfID){
  let ret = DispatchCtrlLib.VoipDispatchCallToConference(ExtNum,ConfID);
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "CallToConference";
    let Parm = new Object();
    Parm.confid = ConfID;
    Parm.extnum = ExtNum;
    Dispatchvoice(Msg, Parm);
  }
}

/**
 * 设置左右话机
 * @param   LeftExt            左话机分机号
 * @param   RightExt           右话机分机号
 */
DispatchvoiceCtrl.DispatchSetDcPhone=function(LeftExt,RightExt){
  let ret = DispatchCtrlLib.VoipDispatchSetDcPhone(LeftExt,RightExt);
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "VoipDispatchSetDcPhone";
    let Parm = new Object();
    Parm.channelId = ret;
    Parm.LeftExt = LeftExt;
    Parm.RightExt = RightExt;
    Dispatchvoice(Msg, Parm);
  }
}

/**
 * 闭铃
 * @param   DcPhone            -1
 */
DispatchvoiceCtrl.VoipDispatchStopRing=function(DcPhone){
  let ret = DispatchCtrlLib.VoipDispatchStopRing(DcPhone);
  if(ret<0){
    console.log("参数错误");
    return;
  }
}

/**
 * IP调度:转接
 * @param   ExtNum            要转接的本方的分机号
 * @param   OtherExtNum            要转接的对方的分机号
 */
DispatchvoiceCtrl.VoipDispatchCallBridge=function(ExtNum, OtherExtNum){
  let ret =DispatchCtrlLib.VoipDispatchCallBridge(ExtNum, OtherExtNum);
  // 整型。小于0 —— 参数错误；大于0 —— 呼叫标识。
  if(ret<0){
    console.log("参数错误");
    return;
  }else {
    let Msg = "VoipDispatchCallBridge";
    let Parm = new Object();
    Parm.ExtNum = ExtNum;
    Parm.OtherExtNum = OtherExtNum;
    Dispatchvoice(Msg, Parm);
    return ret;
  }
}
export { DispatchvoiceCtrl }

